<%--
  Created by IntelliJ IDEA.
  User: qingx
  Date: 2018/12/29
  Time: 16:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<!DOCTYPE html>
<html lang="en">
<head>
    <!-- jsp文件头和头部 -->
    <%@ include file="../base/top.jsp"%>
    <link rel="stylesheet" href="static/ace/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->

                        <form class="form-horizontal" role="form" style="display: -webkit-flex;-webkit-justify-content: center;-webkit-align-items: center;">
                            <div style="width: 70%;">
                                <div class="widget-box">
                                    <div class="widget-header" style="text-align: center">
                                        <h4 class="widget-title">修改课程</h4>
                                    </div>

                                    <div class="widget-main">
                                        <div>
                                            <label>课程编号</label>
                                            <br />
                                            <input class="form-control" id="course-num" maxlength="10" oninput="value=value.replace(/[^\d]/g,'')"/>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>课程名称</label>
                                            <br />
                                            <input class="form-control" id="course-name"/>
                                        </div>
                                        <hr />

                                        <div>
                                            <label >开设学期</label>
                                            <br />
                                            <input class="form-control" id="course-start-term" maxlength="1" oninput="value=value.replace(/[^\d]/g,'')"/>
                                        </div>
                                        <hr />

                                        <div>
                                            <label >学分</label>
                                            <br />
                                            <input class="form-control" id="course-credit">
                                        </div>
                                        <hr />

                                        <div>
                                            <label >学时</label>
                                            <br />
                                            <input class="form-control" id="course-hours" maxlength="3" oninput="value=value.replace(/[^\d]/g,'')">
                                        </div>
                                        <hr />

                                        <div>
                                            <label >课程类别</label>
                                            <br />
                                            <select class="chosen-select form-control" id="course-type" data-placeholder="Choose a State...">
                                                <option></option>
                                                <option>通识教育课程</option>
                                                <option>学科基础课程</option>
                                                <option>专业核心课程</option>
                                                <option>专业拓展课程</option>
                                                <option>专业实践课程</option>
                                                <option>创新创业课程</option>
                                            </select>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>考核方式</label>
                                            <br />
                                            <select class="chosen-select form-control" id="course_assessment_method" data-placeholder="Choose a State...">
                                                <option></option>
                                                <option>考查</option>
                                                <option>考试</option>
                                                <option>答辩</option>
                                            </select>
                                        </div>
                                        <hr />

                                        <div>
                                            <label>课程描述</label>
                                            <textarea class="form-control" id="course-description" maxlength="100" style="height: 80px;resize:none;" placeholder="仅限100字..."></textarea>
                                        </div>

                                        <div class="clearfix form-actions" align="center">
                                            <button class="btn btn-info" type="button" onclick="edit()">
                                                Submit
                                            </button> &nbsp; &nbsp; &nbsp;
                                            <button class="btn" type="reset">
                                                Reset
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>

                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
    <!-- 返回顶部 -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>
</div>
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../base/foot.jsp"%>

<script type="text/javascript">
//    $(top.hangge());//关闭加载状态
    $(function () {
        //下拉框
        if (!ace.vars['touch']) {
            $('.chosen-select').chosen({allow_single_deselect: true});
            $(window)
                .off('resize.chosen')
                .on('resize.chosen', function () {
                    $('.chosen-select').each(function () {
                        var $this = $(this);
                        $this.next().css({'width': $this.parent().width()});
                    });
                }).trigger('resize.chosen');
            $(document).on('settings.ace.chosen', function (e, event_name, event_val) {
                if (event_name != 'sidebar_collapsed') return;
                $('.chosen-select').each(function () {
                    var $this = $(this);
                    $this.next().css({'width': $this.parent().width()});
                });
            });
            $('#chosen-multiple-style .btn').on('click', function (e) {
                var target = $(this).find('input[type=radio]');
                var which = parseInt(target.val());
                if (which == 2) $('#form-field-select-4').addClass('tag-input-style');
                else $('#form-field-select-4').removeClass('tag-input-style');
            });
        }
    });

    //初始化添加数据
    $(document).ready(function(){
        var courseInfo ="${courseInfo}";
        $("#course-num").val("${courseInfo.courseNum}");
        $("#course-name").val("${courseInfo.courseName}");
        $("#course-start-term").val("${courseInfo.courseStartTerm}");
        $("#course-credit").val("${courseInfo.courseCredit}");
        $("#course-hours").val("${courseInfo.courseHours}");
        $("#course-type").val("${courseInfo.courseType}");
        $("#course_assessment_method").val("${courseInfo.courseAssessmentMethod}");
        $("#course-description").html("${courseInfo.courseDescription}");
        //更新select,否则虽然数据更改了，没刷新，结果就是没改
        $('.chosen-select').trigger("chosen:updated");
    });
    
    function edit() {
        if(checkFormats()){
            var data = {
                courseId:"${courseInfo.courseId}",
                courseNum:$("#course-num").val(),
                courseName:$("#course-name").val(),
                courseStartTerm:$("#course-start-term").val(),
                courseCredit:$("#course-credit").val(),
                courseHours:$("#course-hours").val(),
                courseType:$("#course-type").val(),
                courseAssessmentMethod:$("#course_assessment_method").val(),
                courseDescription:$("#course-description").val(),
                talentTrainingProgramId:"123456"
            }
            console.log(data);
            $.ajax({
                type: "POST",
                url: "<%=basePath%>course/editCourseInfo",
                data: data,
                dataType:"json",
                success: function(data){
                    if(data["success"]==true){
                        prompt_alert('success',data["msg"],0);
                    }else{
                        prompt_alert('error',data["msg"],0);
                    }
                },
                error:function(msg){
                    prompt_alert('error',"课程修改失败！",0);
                }
            });
        }
    }
    //数据校验
    function checkFormats() {
         if($("#course-num").val() == "") {
            prompt_alert('warning',"课程编号不得为空",0);
            return false;
         }
         if($("#course-name").val() == "") {
            prompt_alert('warning',"课程名称不得为空",0);
            return false;
         }
         if($("#course-start-term").val() == "") {
            prompt_alert('warning',"开设学期不得为空",0);
            return false;
         }
         if($("#course-credit").val() == "") {
            prompt_alert('warning',"学分不得为空",0);
            return false;
         }
         if($("#course-hours").val() == "") {
            prompt_alert('warning',"学时不得为空",0);
            return false;
         }
         if($("#course-type").val() == "") {
            prompt_alert('warning',"课程类别不得为空",0);
            return false;
         }
        if($("#course_assessment_method").val() == "") {
            prompt_alert('warning',"考核方式不得为空",0);
            return false;
        }
        if($("#course-description").val() == "") {
            prompt_alert('warning',"联系方式不得为空",0);
            return false;
        }
        return true;
    }
</script>
</body>
</html>
